package com.szeldon.pj.jps.qres;

public class BooleanResult extends AbstractQueryResult {

	private boolean bool;

	/**
	 * 
	 * @param bool
	 */
	public BooleanResult(boolean bool) {
		this.bool = bool;
	}

	@Override
	public String toString() {
		return "boolean(" + bool + ")";
	}

	public boolean getBool() {
		return bool;
	}

	@Override
	public int compareTo(AbstractQueryResult result) {
		if (result instanceof BooleanResult) {
			boolean resultBool = ((BooleanResult) result).getBool();
			if (bool == resultBool) {
				return 0;
			} else if (bool == false) {
				return -1;
			} else {
				return 1;
			}
		} else {
			throw new IllegalStateException("Boolean result can't be compared with " + result.getClass().getName()
					+ " result.");
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj.getClass().equals(this.getClass())) {
			BooleanResult objResult = (BooleanResult) obj;
			if (bool == objResult.getBool()) {
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}
}
